﻿package mortal.game.view.guildNew.shop
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.mvc.core.*;

    public class GuildNewShopCell extends GCellRenderer
    {
        protected var _bg:GBitmap;
        protected var _item:BaseItem;
        protected var _nameTxt:GTextFiled;
        protected var _buyBtn:GLoadingButton;
        protected var _limitNum:GTextFiled;
        protected var _donate:GTextFiled;
        protected var _resTxt:GTextFiled;
        protected var _numStep:GNumericStepper;
        private var _tGuildShopItem:TGuildShopSell;
        private var _sguildShopItem:SGuildShopItem;

        public function GuildNewShopCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gBitmap(ImagesConst.GoodsBg, 0, 0, this);
            this._item = UIFactory.getUICompoment(BaseItem);
            this._item.setItemStyle(ItemStyleConst.Mid, ImagesConst.ShopItemBg, 6, 6);
            UIFactory.setObjAttri(this._item, 22, 33, -1, -1, this);
            this._nameTxt = UIFactory.gTextField("", 0, 3, 240, 25, this, GlobalStyle.textFormatLv.setSize(13).center());
            this._buyBtn = UIFactory.gLoadingButton(ImagesConst.LineOffCopyCellBtn_upSkin, 181, 72, 47, 25, this);
            this._buyBtn.label = "" + Language.getString(71599);
            this._limitNum = UIFactory.gTextField("", 94, 32, 100, 20, this, GlobalStyle.textFormatHuang);
            this._donate = UIFactory.gTextField("", 93, 53, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._resTxt = UIFactory.gTextField("", 14, 71, 80, 20, this, GlobalStyle.textFormatLv.center());
            this._numStep = UIFactory.gNumericStepper(95, 75, 50, 20, this, 99, 1, "NumericStepper", GlobalStyle.textFormatBai.right());
            this._numStep.value = 1;
            this._buyBtn.configEventListener(MouseEvent.CLICK, this.buyHd);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg = null;
            this._item = null;
            this._nameTxt = null;
            this._buyBtn = null;
            this._limitNum = null;
            this._donate = null;
            this._resTxt = null;
            this._numStep = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            this._sguildShopItem = param1.sguildShopItem as SGuildShopItem;
            this._tGuildShopItem = param1.tGuildShopItem as TGuildShopSell;
            this._item.itemData = new ItemData(this._tGuildShopItem.itemCode);
            this._nameTxt.htmlText = ItemsUtil.getItemName(this._item.itemData);
            this._donate.text = Language.getString(71600) + this._sguildShopItem.price.toString();
            this._resTxt.text = Language.getString(71601) + this._sguildShopItem.leftAmount.toString();
            this._limitNum.text = Language.getString(71602) + this._sguildShopItem.buyLimit.toString();
            this._numStep.maximum = this._sguildShopItem.buyLimit;
            this._numStep.drawNow();
            return;
        }// end function

        private function buyHd(event:MouseEvent) : void
        {
            var _loc_2:* = Cache.instance.guild.selfGuildInfo.selfInfo.contribution;
            if (this._sguildShopItem.leftAmount == 0 || this._sguildShopItem.leftAmount < this._numStep.value)
            {
                MsgManager.showMouseMsg(Language.getString(71603), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (this._sguildShopItem.buyLimit == 0 || this._sguildShopItem.buyLimit < this._numStep.value)
            {
                MsgManager.showMouseMsg(Language.getString(71604), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (_loc_2 < this._tGuildShopItem.price * this._numStep.value)
            {
                MsgManager.showMouseMsg(Language.getString(71605), MsgRollTipsType.msgRollTips3);
                return;
            }
            if (Cache.instance.pack.backPackCache.isPackFull(this._tGuildShopItem.itemCode, this._numStep.value))
            {
                MsgManager.showMouseMsg(Language.getString(71606), MsgRollTipsType.msgRollTips3);
                return;
            }
            var _loc_3:Object = {};
            _loc_3.itemCode = this._tGuildShopItem.itemCode;
            _loc_3.num = this._numStep.value;
            Dispatcher.dispatchEvent(new DataEvent(GuildNewLocalEvent.GuildNewShopBuy, _loc_3));
            return;
        }// end function

    }
}
